import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sinosheets/components/GBWebView/gb_webview.dart';
import 'package:sinosheets/utils/common_utils/log_util.dart';
import 'package:sinosheets/utils/theme/style_utils.dart';

import 'logic.dart';

class SinoWebPage extends StatefulWidget {
  const SinoWebPage({Key? key}) : super(key: key);

  @override
  State<SinoWebPage> createState() => _SinoWebPageState();
}

class _SinoWebPageState extends State<SinoWebPage> {
  final SinoWebLogic logic = Get.put(SinoWebLogic());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SinoWebLogic>(builder: (get) {
      return AnimatedSwitcher(
          duration: Duration(milliseconds: 300),
          child: get.webReady
              ? Stack(
                  children: [
                    SafeArea(
                      child: GBWebView(
                        key: ValueKey('url_webview'),
                        url: get.url,
                        onWebViewCreated: (controller) {},
                        onLoadStart: (InAppWebViewController controller, Uri? url) {
                          LogUtil.e('=======onLoadStart======');
                        },
                        onLoadStop: (InAppWebViewController controller, Uri? url) {
                          LogUtil.e('=======onLoadStop======');
                        },
                        gestureRecognizers: {
                          Factory(() => VerticalDragGestureRecognizer()),
                        },
                      ),
                    ),
                    Positioned(
                      bottom: 80.r,
                      right: 10.r,
                      child: Material(
                        color: Colors.transparent,
                        child: InkWell(
                          borderRadius: BorderRadius.circular(20.r),
                          onTap: () => Navigator.of(context).maybePop(),
                          child: Container(
                            width: 40.r,
                            height: 40.r,
                            decoration: BoxDecoration(
                              color: ColorUtils.themeColor,
                              shape: BoxShape.circle,
                              boxShadow: [
                                BoxShadow(
                                  color: Colors.black.withOpacity(0.08),
                                  blurRadius: 8.r,
                                  offset: Offset(0, 2.r),
                                ),
                              ],
                            ),
                            child: Icon(Icons.home, color: Colors.white, size: 24.r),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              : Container());
    });
  }

  @override
  void dispose() {
    Get.delete<SinoWebLogic>();
    super.dispose();
  }
}
